using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
/// <summary>
/// 想做3个事情：
/// 1.延帧调用；
/// 2.整合之前Delay携程调用链
/// 3.应用层面的最后一击（或大招）延迟动画
/// 4.Delay Invoke()
/// </summary>
public class DelayUtils
{
    static DelayUtils _inst;
    public static DelayUtils Inst {
        get
        {
            if(_inst==null)
                _inst = new DelayUtils();
            return _inst;
        }
    }

    public void Execute(MonoBehaviour mono, Action<GameObject> act, GameObject obj,float delay = 0.01f)
    {
        mono.StartCoroutine(DelayCor(act, obj,delay));
    }

    IEnumerator DelayCor(Action<GameObject> act, GameObject go, float delaySec)
    {
        yield return new WaitForSeconds(delaySec);
        act(go);
    }

    public void Execute(MonoBehaviour mono, Action act, float delay = 0.01f)
    {
        mono.StartCoroutine(DelayCor(act, delay));
    }

    IEnumerator DelayCor(Action act,float delays)
    {
        yield return new WaitForSeconds(delays);
        act();
    }
}
